package com.heihei.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heihei.common.page.Query;
import com.heihei.common.response.ResponseVO;
import com.heihei.entity.HelloWorldEntity;
import com.heihei.service.HelloWorldService;
import com.heihei.vo.HelloWorldTreeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author duanhengfei
 * @since 2021-02-24
 */
@Api(tags = {"HelloWorld"})
@RestController
@RequestMapping("/hello-world")
public class HelloWorldController {
    @Resource
    private HelloWorldService helloWorldService;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public ResponseVO<Long> add(@RequestBody HelloWorldEntity entity) {
        return helloWorldService.add(entity);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public ResponseVO<String> update(@RequestBody HelloWorldEntity entity) {
        return helloWorldService.edit(entity);
    }

    @ApiOperation(value = "列表 分页查询")
    @GetMapping("/list")
    public ResponseVO<IPage<HelloWorldEntity>> list(HelloWorldEntity param, Query query) {
        return helloWorldService.listConditional(param, query);
    }

    @ApiOperation(value = "获取详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "number")
    @PostMapping("/get/{id}")
    public ResponseVO<HelloWorldEntity> get(@PathVariable("id") Long id) {
        return helloWorldService.get(id);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "number")
    @PostMapping("/delete/{id}")
    public ResponseVO<String> delete(@PathVariable("id") Long id) {
        return helloWorldService.delete(id);
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("/delete-batch")
    public ResponseVO<String> delete(@RequestBody List<Long> idList) {
        return helloWorldService.deleteBatch(idList);
    }

    @ApiOperation(value = "查询树结构")
    @PostMapping("/tree")
    public ResponseVO<List<HelloWorldTreeVO>> tree(){
        return helloWorldService.tree();
    }

}
